<div class="row">
<div class="button-container mb10">
<?php 
    echo Yii::app()->user->checkAccess('model|add')?CHtml::link('添加模型','javascript:void(0);',array('class'=>'button editShow' ,'url'=>$this->createUrl('model/add' ))):'';
?>
</div>
<!--表格数据-->

<table class="table table-bordered table-striped dataGrid">
        <thead>
            <tr>
                <th style="width: 80px;"><?php echo $this->_attributeLabels['model_id'] ?></th>
                <th><?php echo $this->_attributeLabels['model_name'] ?></th>
                <th><?php echo $this->_attributeLabels['table_name'] ?></th>
                <th><?php echo $this->_attributeLabels['description'] ?></th>
				<th><?php echo $this->_attributeLabels['disable'] ?></th>
				<th style="width: 140px;">操作</th>
            </tr>
        </thead>
        <tbody>
        <?php if( !empty($list) ){foreach( $list as $aVal ){ ?>
            <tr>
                <td><?php echo $aVal['model_id'] ?></td>
                <td><?php echo $aVal['model_name'] ?></td>
                <td><?php echo $aVal['table_name'] ?></td>
                <td><?php echo $aVal['description'] ?></td>
                <td>
                <?php
                    $sTextRed = $aVal['disable']==1 ? '' : 'red';
                    echo Yii::app()->user->checkAccess('model|ajaxDiable') ? 
                         CHtml::link($aVal['disable']==1 ? '禁用' : '启用' ,'javascript:void(0)' ,array('url'=>$this->createUrl('model/ajaxDisable' ,array('model_id'=>$aVal['model_id'])) ,'class'=>"ajaxOperateReplace $sTextRed")) : '';
                ?>
                </td>
                <td>
                <?php
                    echo Yii::app()->user->checkAccess('model|priview') ?
                         CHtml::link('预览' ,$this->createUrl('model/priview' ,array('model_id'=>$aVal['model_id'])) ,array('target'=>'_blank')) ."\n" : '';
                    echo Yii::app()->user->checkAccess('model|modelfield') ?
                         CHtml::link('字段管理' ,$this->createUrl('model/modelfield' ,array('model_id'=>$aVal['model_id']))) ."\n" : '';
                    echo Yii::app()->user->checkAccess('model|editShow') ?
                         CHtml::link('编辑' ,'javascript:void(0);',array('class'=>'editShow' ,'isedit'=>'1' ,'url'=>$this->createUrl('model/edit' ,array('model_id'=>$aVal['model_id'])))) ."\n" : '';
                    echo Yii::app()->user->checkAccess('model|delete') ?
                         CHtml::link('删除','javascript:void(0);',array('url'=>$this->createUrl('model/delete' ,array('model_id'=>$aVal['model_id'])) ,'class'=>'delete')) : '';
                ?>
                </td>
            </tr>
        <?php }} ?>               
        </tbody>
</table>
<!-- 分页page start -->
<div class="table-bottom-operate">
    <div class="inline pull-left table-operate">
    </div>
    <div class="inline pull-right page">
        <?php //$this->widget('LinkPager',array('pages' => $pages)); ?>
    </div>
	
</div>
<!-- 分页page end -->
</div>
<script type="text/javascript">
function add(url ,isedit){
        var Overlay = BUI.Overlay,
        Form = BUI.Form;
        var form,
        dialog = new Overlay.Dialog({
            title:'添加/编辑模型',
            width:600,
            height:500,
            loader : {
              url : url,
              autoLoad : false, //不自动加载
              lazyLoad : false,
              callback : function(){
                var node = dialog.get('el').find('form');//查找内部的表单元素
                form = new Form.HForm({
                  srcNode : node,
                  autoRender : true
                });
                if(!isedit){
                //验证表单名称
                var aField = form.getField('CmsModel[table_name]');
                  aField.set('remote',{
                     url : '<?php echo $this->createUrl('model/ajaxVerifyTableName') ?>',
                     dataType:'json',//默认为字符串
                     callback : function(data){
                       if(data.err==0){
                        return '';
                       }else{
                        return data.msg;
                       }
                     }
                  });
                }
              }
            },
            mask:false,
            success : function(){
              //可以直接action 提交
              //alert(params);
              form && form.submit(); //也可以form.ajaxSubmit(params);
            }
          });
      //dialog.show();
      form && form.destroy(); //移除掉之前的表单
      dialog.show();
      //var params = {a : count}; //加载表单的参数
      dialog.get('loader').load();
}
      var count = 0;
      $('.editShow').on('click',function () {
        
        var url = $(this).attr('url') ,isedit = false;
        if($(this).attr('isedit')) isedit = true;
        add(url ,isedit);
      });
  </script>
